﻿using UnityEngine;
using System.Collections;

// 玩家最终的结果
using System;
using System.Collections.Generic;


public enum InputAction
{
	PressDown,
	RaiseUp,
	ShortClick,
	Click,
	SliderUp,
}

public class InputEventArgs : EventArgs
{
	public InputEventArgs(InputAction act)
	{
		action = act;
	}

	private InputAction action;
	public InputAction Action
	{
		get {return action;}
		set {action = value;}
	}
}

public class InputControlCenter : MonoBehaviour {
	public event EventHandler<InputEventArgs> evtUserInput;

	public float upDistence;
	public int circleFrame;
	
	private List<float> deltaPos;
	private bool signaled;

	// Use this for initialization
	void Start () {
		deltaPos = new List<float> ();
		signaled = false;
	}
	
	// Update is called once per frame
	void Update () {
		RaycastHit rayHit;
		if (UICamera.Raycast (Input.mousePosition, out rayHit))
			return;

		// test for pressdown
		if (Input.GetButtonDown ("Fire1")) {
			if (null != evtUserInput)
				evtUserInput (this, new InputEventArgs (InputAction.PressDown));
		}

		// test for raiseup
		if (Input.GetButtonUp ("Fire1")) {
			if (null != evtUserInput)
				evtUserInput (this, new InputEventArgs (InputAction.RaiseUp));
		}

		// test for dragging up, plus all move distance together during circleFrame
		if(Input.GetButton("Fire1")){
			if(signaled)
				return;
			
			if(deltaPos.Count >=  circleFrame)
			{
				deltaPos.RemoveAt(0);
			}
			
			deltaPos.Add(Input.GetAxis("Mouse Y"));
			float totalPos = 0;
			foreach(float fDelta in deltaPos){
				totalPos += fDelta;
			}
			if(totalPos > upDistence){
				signaled = true;
				if (null != evtUserInput)
					evtUserInput (this, new InputEventArgs (InputAction.SliderUp));
			}
		}
		else
		{
			deltaPos.Clear();
			signaled = false;
		}
	}
}
